package com.example.hf_v1.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hf_v1.entity.Face;
import com.example.hf_v1.entity.Hairstyleattributes;
import com.example.hf_v1.entity.Hairstyles;
import com.example.hf_v1.entity.Vo.HairstylesVo;
import com.example.hf_v1.mapper.HairstylesMapper;
import com.example.hf_v1.service.HairstylesService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HairstylesServiceImpl extends ServiceImpl<HairstylesMapper, Hairstyles> implements HairstylesService {

    @Resource
    private HairstylesMapper hairstylesMapper;

    @Override
    public List<HairstylesVo> selectAllHairstyles() {
        MPJLambdaWrapper<Hairstyles> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAs(Hairstyles::getHairstyleId, HairstylesVo::getHairstyleId)
                .selectAs(Hairstyles::getAttributeId,HairstylesVo::getAttributeId)
                .selectAs(Hairstyles::getName, HairstylesVo::getName)
                .selectAs(Hairstyles::getDescription, HairstylesVo::getDescription)
                .selectAs(Hairstyles::getImageUrl, HairstylesVo::getImageUrl)
                .selectAs(Hairstyles::getCreatedAt, HairstylesVo::getCreatedAt)
                .selectAs(Hairstyles::getUpdatedAt, HairstylesVo::getUpdatedAt)
                .selectAs(Hairstyles::getLocal3dUrl, HairstylesVo::getLocal3dUrl)
                .selectAs(Hairstyles::getHairKindName,HairstylesVo::getHairKindName)
                .leftJoin(Hairstyleattributes.class,Hairstyleattributes::getAttributeId,Hairstyles::getAttributeId)
                .leftJoin(Face.class,Face::getFaceId,Hairstyles::getHairstyleFaceId)
                .selectAs(Hairstyleattributes::getAttributeName,HairstylesVo::getAttributeName)
                .selectAs(Hairstyleattributes::getAttributeValue, HairstylesVo::getAttributeValue)
                .selectAs(Hairstyleattributes::getCurliness,HairstylesVo::getCurliness)
                .selectAs(Hairstyleattributes::getHairLong,HairstylesVo::getHairLong)
                .selectAs(Hairstyleattributes::getPrem,HairstylesVo::getPrem)
                .selectAs(Hairstyleattributes::getHairDyeing,HairstylesVo::getHairDyeing)
                .selectAs(Face::getFaceName,HairstylesVo::getFaceName)
                .selectAs(Face::getFaceContact,HairstylesVo::getFaceContact)
                .selectAs(Face::getFaceFeature,HairstylesVo::getFaceFeature)
                .selectAs(Face::getFaceNoHairstyles,HairstylesVo::getFaceNoHairstyles)
                .selectAs(Face::getFaceHairLengthAdvice,HairstylesVo::getFaceHairLengthAdvice)
                .selectAs(Face::getFaceHairFringeAdvice,HairstylesVo::getFaceHairFringeAdvice)
                .orderByAsc(Hairstyles::getHairstyleId);
        return hairstylesMapper.selectJoinList(HairstylesVo.class,wrapper);
    }

    @Override
    public List<HairstylesVo> selectAllHairstylesByType(String type) {
        MPJLambdaWrapper<Hairstyles> wrapperByType = new MPJLambdaWrapper(Hairstyles.class);
        wrapperByType.selectAs(Hairstyles::getHairstyleId, HairstylesVo::getHairstyleId)
                .selectAs(Hairstyles::getAttributeId,HairstylesVo::getAttributeId)
                .selectAs(Hairstyles::getName, HairstylesVo::getName)
                .selectAs(Hairstyles::getDescription, HairstylesVo::getDescription)
                .selectAs(Hairstyles::getImageUrl, HairstylesVo::getImageUrl)
                .selectAs(Hairstyles::getCreatedAt, HairstylesVo::getCreatedAt)
                .selectAs(Hairstyles::getUpdatedAt, HairstylesVo::getUpdatedAt)
                .selectAs(Hairstyles::getLocal3dUrl, HairstylesVo::getLocal3dUrl)
                .selectAs(Hairstyles::getHairKindName,HairstylesVo::getHairKindName)
                .leftJoin(Hairstyleattributes.class,Hairstyleattributes::getAttributeId,Hairstyles::getAttributeId)
                .leftJoin(Face.class,Face::getFaceId,Hairstyles::getHairstyleFaceId)
                .selectAs(Hairstyleattributes::getAttributeName,HairstylesVo::getAttributeName)
                .selectAs(Hairstyleattributes::getAttributeValue, HairstylesVo::getAttributeValue)
                .selectAs(Hairstyleattributes::getCurliness,HairstylesVo::getCurliness)
                .selectAs(Hairstyleattributes::getHairLong,HairstylesVo::getHairLong)
                .selectAs(Hairstyleattributes::getPrem,HairstylesVo::getPrem)
                .selectAs(Hairstyleattributes::getHairDyeing,HairstylesVo::getHairDyeing)
                .selectAs(Face::getFaceName,HairstylesVo::getFaceName)
                .selectAs(Face::getFaceContact,HairstylesVo::getFaceContact)
                .selectAs(Face::getFaceFeature,HairstylesVo::getFaceFeature)
                .selectAs(Face::getFaceNoHairstyles,HairstylesVo::getFaceNoHairstyles)
                .selectAs(Face::getFaceHairLengthAdvice,HairstylesVo::getFaceHairLengthAdvice)
                .selectAs(Face::getFaceHairFringeAdvice,HairstylesVo::getFaceHairFringeAdvice)
                .eq(type!=null,Hairstyleattributes::getAttributeName,type).list();
        return hairstylesMapper.selectJoinList(HairstylesVo.class,wrapperByType);
    }

    @Override
    public List<HairstylesVo> selectHairstyleByName(String name) {
        MPJLambdaWrapper<Hairstyles> wrapperByName = new MPJLambdaWrapper(Hairstyles.class);
        wrapperByName.selectAs(Hairstyles::getHairstyleId, HairstylesVo::getHairstyleId)
                .selectAs(Hairstyles::getAttributeId,HairstylesVo::getAttributeId)
                .selectAs(Hairstyles::getName, HairstylesVo::getName)
                .selectAs(Hairstyles::getDescription, HairstylesVo::getDescription)
                .selectAs(Hairstyles::getImageUrl, HairstylesVo::getImageUrl)
                .selectAs(Hairstyles::getCreatedAt, HairstylesVo::getCreatedAt)
                .selectAs(Hairstyles::getUpdatedAt, HairstylesVo::getUpdatedAt)
                .selectAs(Hairstyles::getLocal3dUrl, HairstylesVo::getLocal3dUrl)
                .selectAs(Hairstyles::getHairKindName,HairstylesVo::getHairKindName)
                .leftJoin(Hairstyleattributes.class,Hairstyleattributes::getAttributeId,Hairstyles::getAttributeId)
                .leftJoin(Face.class,Face::getFaceId,Hairstyles::getHairstyleFaceId)
                .selectAs(Hairstyleattributes::getAttributeName,HairstylesVo::getAttributeName)
                .selectAs(Hairstyleattributes::getAttributeValue, HairstylesVo::getAttributeValue)
                .selectAs(Hairstyleattributes::getCurliness,HairstylesVo::getCurliness)
                .selectAs(Hairstyleattributes::getHairLong,HairstylesVo::getHairLong)
                .selectAs(Hairstyleattributes::getPrem,HairstylesVo::getPrem)
                .selectAs(Hairstyleattributes::getHairDyeing,HairstylesVo::getHairDyeing)
                .selectAs(Face::getFaceName,HairstylesVo::getFaceName)
                .selectAs(Face::getFaceContact,HairstylesVo::getFaceContact)
                .selectAs(Face::getFaceFeature,HairstylesVo::getFaceFeature)
                .selectAs(Face::getFaceNoHairstyles,HairstylesVo::getFaceNoHairstyles)
                .selectAs(Face::getFaceHairLengthAdvice,HairstylesVo::getFaceHairLengthAdvice)
                .selectAs(Face::getFaceHairFringeAdvice,HairstylesVo::getFaceHairFringeAdvice)
                .like(name!=null,Hairstyles::getName,"%"+name +"%").list();
        return hairstylesMapper.selectJoinList(HairstylesVo.class, wrapperByName);
    }

    @Override
    public List<HairstylesVo> selectHairstyleByFace(String faceType) {
        MPJLambdaWrapper<Hairstyles> wrapper = new MPJLambdaWrapper(Hairstyles.class);
        wrapper.selectAs(Hairstyles::getHairstyleId, HairstylesVo::getHairstyleId)
                .selectAs(Hairstyles::getAttributeId,HairstylesVo::getAttributeId)
                .selectAs(Hairstyles::getName, HairstylesVo::getName)
                .selectAs(Hairstyles::getDescription, HairstylesVo::getDescription)
                .selectAs(Hairstyles::getImageUrl, HairstylesVo::getImageUrl)
                .selectAs(Hairstyles::getCreatedAt, HairstylesVo::getCreatedAt)
                .selectAs(Hairstyles::getUpdatedAt, HairstylesVo::getUpdatedAt)
                .selectAs(Hairstyles::getLocal3dUrl, HairstylesVo::getLocal3dUrl)
                .selectAs(Hairstyles::getHairKindName,HairstylesVo::getHairKindName)
                .leftJoin(Hairstyleattributes.class,Hairstyleattributes::getAttributeId,Hairstyles::getAttributeId)
                .leftJoin(Face.class,Face::getFaceId,Hairstyles::getHairstyleFaceId)
                .selectAs(Hairstyleattributes::getAttributeName,HairstylesVo::getAttributeName)
                .selectAs(Hairstyleattributes::getAttributeValue, HairstylesVo::getAttributeValue)
                .selectAs(Hairstyleattributes::getCurliness,HairstylesVo::getCurliness)
                .selectAs(Hairstyleattributes::getHairLong,HairstylesVo::getHairLong)
                .selectAs(Hairstyleattributes::getPrem,HairstylesVo::getPrem)
                .selectAs(Hairstyleattributes::getHairDyeing,HairstylesVo::getHairDyeing)
                .selectAs(Face::getFaceName,HairstylesVo::getFaceName)
                .selectAs(Face::getFaceContact,HairstylesVo::getFaceContact)
                .selectAs(Face::getFaceFeature,HairstylesVo::getFaceFeature)
                .selectAs(Face::getFaceNoHairstyles,HairstylesVo::getFaceNoHairstyles)
                .selectAs(Face::getFaceHairLengthAdvice,HairstylesVo::getFaceHairLengthAdvice)
                .selectAs(Face::getFaceHairFringeAdvice,HairstylesVo::getFaceHairFringeAdvice)
                .like(faceType!=null,Face::getFaceName,"%" + faceType + "%")
                .list();
        return hairstylesMapper.selectJoinList(HairstylesVo.class, wrapper);
    }


}
